Q and A - II
echo $_COOKIE['user'];
$_GET sends data via the URL, $_POST sends it via HTTP body (more secure).
Contains information about headers, paths, and script locations.
Terminates script execution immediately.
Using $_FILES superglobal and move_uploaded_file() function.
$file = fopen("data.txt", "r");
echo fread($file, filesize("data.txt"));
fclose($file);
Managing runtime errors using try, catch, and throw.
function greet($name) {
return "Hello, $name!";
}
Local, Global, Static, and Parameter scope.
A method of programming that uses objects and classes to organize code.
class Person {
public $name;
function sayHello() {
echo "Hello!";
}
}
$person = new Person();
$person->sayHello();
public, protected, and private.
When a class inherits properties and methods from another class using the extends keyword.
An interface defines methods that must be implemented by a class.
Traits allow code reuse across classes without inheritance.
try {
throw new Exception("Error occurred");
} catch (Exception $e) {
echo $e->getMessage();
}
They work like include and require, but prevent multiple inclusions of the same file.
Using password_hash() and password_verify() for passwords.
mail("user@example.com", "Subject", "Message", "From: admin@example.com");
Special methods starting with __ like __construct(), __destruct(), __get(), etc.
A dependency manager for installing and managing PHP libraries.
A PHP web framework that follows the MVC (Model-View-Controller) architecture.
== is case-insensitive in type juggling; strcmp() is case-sensitive and returns integer values.
Use prepared statements or parameterized queries via PDO or MySQLi.